<?php

/**
 * @Desc:
 * @author dasheng@baofu.com(大圣)
 * @datetime 2025/4/5 22:43
 */
require_once "../../Init/init.php";

use App\baocaitong3\Entity\FileNameEntity as FileName;
use App\baocaitong3\Entity\PostFilesParmsEntity as PostFilesParms;
use App\baocaitong3\Entity\SyncUploadFileEntity as SyncUploadFile;
use App\baocaitong3\SecurityUtil\NewRsaUtil;
use App\baocaitong3\Util\HttpClient;
use App\baocaitong3\Util\Log;
use App\baocaitong3\Util\Tools;

try {
    $OrderType = "0";
    $filezip = "G:\\pict\\idphoto.zip";

    echo "HYES";
    $suf = new SyncUploadFile();
    $suf->accType="2";
    $suf->transSerialNo = Tools::getTsnOderid("TSN");
    $suf->businessParams = "";

    $file101 = new FileName();
    $file101->fileName = "business_license";
    $file101->fileType = "101";

    $file102 = new FileName();
    $file102->fileName = "acc_open_license";
    $file102->fileType = "102";

    $file104 = new FileName();
    $file104->fileName = "id_front";
    $file104->fileType = "104";

    $file111 = new FileName();
    $file111->fileName = "id_reverse";
    $file111->fileType = "111";

    $suf->AddFileNameMap($file101);
    $suf->AddFileNameMap($file102);
    $suf->AddFileNameMap($file104);
    $suf->AddFileNameMap($file111);

    $pfp = new PostFilesParms();
    //$pfp->file = curl_file_create(realpath($filezip),mime_content_type($filezip),basename($filezip));

    Log::EchoFormat(realpath($filezip).",".mime_content_type($filezip).",".basename($filezip));
    $sufJson = json_encode($suf);
    Log::EchoFormat("JSON".$sufJson);

    $pfp->memberId =$GLOBALS["MemberId"];
    $pfp->terminalId = $GLOBALS["TerminalId"];
    $pfp->orderType = $OrderType;
    $pfp->content = NewRsaUtil::encryptByPfx($sufJson,$GLOBALS["PFX_PATH"],$GLOBALS["KeyPwd"]);
    $returnstr = HttpClient::MultiPost($pfp,"https://vgw.baofoo.com/baofu-upload-trade/trade/syncUploadFile",$filezip);
    Log::EchoFormat($returnstr);
    if(empty($returnstr)) throw new Exception("请求返回为空！");
    $debyresult = NewRsaUtil::decrptByPub($returnstr,$GLOBALS["CER_PATH"]);
    Log::EchoFormat("解密：".$debyresult);
    $resultObj = json_decode($debyresult,true);
    if($resultObj["success"])
    {
        Log::EchoFormat("流水号：".$resultObj["result"]["transSerialNo"]);
        foreach ($resultObj["result"]["dfsFileNotifyList"] as $item)
        {
            Log::EchoFormat("文件：".json_encode($item));
        }
    }
}catch (Exception $ex){
    echo $ex->getMessage();
}
